package com.ruoyi.business.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.business.domain.HistoryRecords;
import com.ruoyi.business.service.IHistoryRecordsService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 合同历史记录Controller
 *
 * @author ruoyi
 * @date 2025-02-13
 */
@RestController
@RequestMapping("/records")
public class HistoryRecordsController extends BaseController
{
    @Autowired
    private IHistoryRecordsService historyRecordsService;

    /**
     * 20250213 云计算-宏烨找房-05-王江波-我的合同任务工单V1.1-查询合同历史记录列表
     */
    @RequiresPermissions("business:records:list")
    @GetMapping("/list")
    public TableDataInfo list(HistoryRecords historyRecords)
    {
        startPage();
        List<HistoryRecords> list = historyRecordsService.selectHistoryRecordsList(historyRecords);
        return getDataTable(list);
    }

    /**
     * 20250213 云计算-宏烨找房-05-王江波-我的合同任务工单V1.1-导出合同历史记录列表
     */
    @RequiresPermissions("business:records:export")
    @Log(title = "合同历史记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HistoryRecords historyRecords)
    {
        List<HistoryRecords> list = historyRecordsService.selectHistoryRecordsList(historyRecords);
        ExcelUtil<HistoryRecords> util = new ExcelUtil<HistoryRecords>(HistoryRecords.class);
        util.exportExcel(response, list, "合同历史记录数据");
    }

    /**
     * 20250213 云计算-宏烨找房-05-王江波-我的合同任务工单V1.1-获取合同历史记录详细信息
     */
    @RequiresPermissions("business:records:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(historyRecordsService.selectHistoryRecordsById(id));
    }

    /**
     * 20250213 云计算-宏烨找房-05-王江波-我的合同任务工单V1.1-新增合同历史记录
     */
    @RequiresPermissions("business:records:add")
    @Log(title = "合同历史记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HistoryRecords historyRecords)
    {
        return toAjax(historyRecordsService.insertHistoryRecords(historyRecords));
    }

    /**
     * 20250213 云计算-宏烨找房-05-王江波-我的合同任务工单V1.1-修改合同历史记录
     */
    @RequiresPermissions("business:records:edit")
    @Log(title = "合同历史记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HistoryRecords historyRecords)
    {
        return toAjax(historyRecordsService.updateHistoryRecords(historyRecords));
    }

    /**
     * 20250213 云计算-宏烨找房-05-王江波-我的合同任务工单V1.1-删除合同历史记录
     */
    @RequiresPermissions("business:records:remove")
    @Log(title = "合同历史记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(historyRecordsService.deleteHistoryRecordsByIds(ids));
    }
}